package com.azt.front.action.brand;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.util.WebUtils;

import com.azt.api.pojo.Category;
import com.azt.api.pojo.RecommendBrand;
import com.azt.api.service.ProCategoryService;
import com.azt.api.service.RecommendBrandService;
import com.azt.front.action.BaseAction;
import com.azt.model.AjaxJson;
import com.azt.utils.CommonUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

/**
 * Created by zhoutianchi on 2016/12/19.
 */

@Controller
@RequestMapping("/brand")
public class BrandAction  extends BaseAction{

	@Autowired
	private RecommendBrandService recommendBrandService;
	
	@Autowired
	private ProCategoryService proCategoryService;
	
    @RequestMapping("/list")
    public String  brandList(Model model){

		//产品分类
		List<Category> categoryList = proCategoryService.findTopCategory();


		model.addAttribute("categoryList", categoryList);
        return "brand/list";
    }

    /**
	 * 品牌推荐搜索
	 * @param categorySId 产品分类
	 * @param paraNo 当前页码
	 * @param showSize 每行显示数量
	 * @param rowSize 每页显示行数
	 * */
	@ResponseBody
	@RequestMapping(value = "/searchBrand", method = RequestMethod.POST)
	public AjaxJson searchBrand() {
		Map param = WebUtils.getParametersStartingWith(request, null);
		
		int pageNo = getParaToInt("pageNo", 1);		//当前页码
		int showSize = getParaToInt("showSize", 4);	//每行显示数量
		int rowSize = getParaToInt("rowSize", 4);	//每页显示行数

		Page page = PageHelper.startPage(pageNo, showSize * rowSize);
		List<RecommendBrand> list = recommendBrandService.searchBrand(param);

		int totalAll = recommendBrandService.getTotalCount();
		
		Map map = new HashMap();
		map.put("data", CommonUtil.splitList(list, showSize));
		map.put("pages", page.getPages());		//总页数
		map.put("total", page.getTotal());		//查询出的总数
		map.put("totalAll", totalAll);			//所有总数
		return AjaxJson.success().setAttributes(map);
	}

    
}
